include("shared.lua");
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
-- Setting up all the different properties of our melon.
ENT.Delay = 1;
ENT.Healthlol = 1000;
ENT.DeathRadius = 250;
ENT.DeathMagnitude = 250;
ENT.MovingForce = 0;
ENT.MinRange = 0;
ENT.MelonModel = "models/props_wasteland/laundry_washer001a.mdl"

function ENT:Initialize()
self:Setup();
    local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:SetMass(100000)
		phys:EnableMotion(false)
	end
	if (self.Team == 1) then
		self.Entity:SetColor (255, 0, 0, 255);
	end
	if (self.Team == 2) then
		self.Entity:SetColor (0, 0, 255, 255);
	end
	if (self.Team == 3) then
		self.Entity:SetColor (0, 255, 0, 255);
	end
	if (self.Team == 4) then
		self.Entity:SetColor (255, 255, 0, 255);
	end
	if (self.Team == 5) then
	self.Entity:SetColor (255, 0, 255, 255);
	end
	if (self.Team == 6) then
	self.Entity:SetColor (0, 255, 255, 255);
	end
end

function ENT:Think()
local entz = ents.FindInSphere(self.Entity:GetPos(),100)
if WMPause == true then return end
	for k, v in pairs(entz) do
		if v:GetClass() == "lap_harvester" then
		  if v:GetTable().Team == self.Team then
		    if v:GetTable().Full == 1 then
          v:GetTable().Full = 0
          local winners = 0
        for k, v in pairs(player.GetAll()) do
		      if (v:GetNetworkedInt( "melonteam" ) == self.Team) then
		      winners = winners + 1;
		      end 
	      end
        	for k, v in pairs(player.GetAll()) do
        	 if (v:GetNetworkedInt( "melonteam" ) == self.Team) then
           local cost = (server_settings.Int( "WM_RezPerHarvest", 2500 ) / winners)
        	 v:SetNetworkedInt( "nrg", v:GetNetworkedInt( "nrg" ) + cost)
        	 local message = "Your NRG:" .. v:GetNetworkedInt( "nrg" ) .. " Income: " .. cost
        	 v:PrintMessage(HUD_PRINTTALK, message)
        	 end
        	end
         end
	      end
	    end
		end
	self.Entity:NextThink(CurTime()+self.Delay);
return true
end

function ENT:OnRemove()
timer.Simple(2, WMDomination)
end